package com.dominator.repository;

import java.math.BigDecimal;
import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import com.dominator.mybatis.dao.T_account_ticketDao;
import com.dominator.mybatis.dao.T_account_ticketPO;
import com.dominator.utils.dao.JdbcHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.dominFramework.core.dao.SqlDao;
import com.dominFramework.core.id.SystemIdUtils;
import com.dominFramework.core.typewrap.Dto;
import com.dominFramework.core.typewrap.Dtos;

@Repository
public class DaoAccountTicket {
	@Resource
	JdbcHelper jh;

	@Autowired
	T_account_ticketDao accountTicketDao;

	@Autowired
	SqlDao sqlDao;

	/**
	 * 添加
	 * 
	 * @param record
	 * @return
	 */
	public Integer insertSelective(T_account_ticketPO record) {
		return accountTicketDao.insert(record);
	}

	/**
	 * 删除
	 * 
	 * @param
	 * @return
	 */
	public Integer deleteByPrimaryKey(String id) {
		return accountTicketDao.deleteByKey(id);
	}

	/**
	 * 修改
	 * 
	 * @param record
	 * @return
	 */
	public Integer updateByPrimaryKey(T_account_ticketPO record) {
		return accountTicketDao.updateByKey(record);
	}

	/**
	 * 查询单条记录
	 * 
	 * @param id
	 * @return
	 */
	public T_account_ticketPO selectByPrimaryKey(String id) {
		T_account_ticketPO row = accountTicketDao.selectByKey(id);
		return row;
	}


	
	/**
	 * 通过用户id查询账户
	 * 
	 * @param
	 * @return
	 */
	public List<T_account_ticketPO> selectByUserId(String userId) {
		Dto qDto = Dtos.newDto("userId", userId);
		List<T_account_ticketPO> list = sqlDao.list("AccountTicket.selectByUserId", qDto);
		return list;
	}
	
	
	/**
	 * 求职代金券
	 * @param userId
	 */
	public void  createResumeTicket(String userId){
		T_account_ticketPO ticket =new T_account_ticketPO();
		ticket.setId(SystemIdUtils.uuid());
		ticket.setCreate_time(new Date());
		ticket.setMoney(new BigDecimal(50));
		ticket.setIs_valid("1");
		ticket.setUser_id(userId);
		accountTicketDao.insert(ticket);
	}
	
	/**
	 * 购买代金券
	 * @param userId
	 */
	public void  createJobTicket(String userId){
		T_account_ticketPO ticket =new T_account_ticketPO();
		for(int i=1;i<=5;i++){
			ticket.clear();
			ticket.setId(SystemIdUtils.uuid());
			ticket.setCreate_time(new Date());
			ticket.setMoney(new BigDecimal(10));
			ticket.setIs_valid("1");
			ticket.setUser_id(userId);
			accountTicketDao.insert(ticket);
		}		
	}

}
